/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package elsimulatorjava;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.TexturePaint;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JComponent;

/**
 *
 * @author plitter
 */
public class Door extends JComponent {

    BufferedImage bImg;
    int elevatorDoorOpening;
    int elevatorDoorHeight;
    Color color;
    int elevatorDoorWidth;
    int xCoordRight;
    
    public Door(int elevatorDoorWidth, int elevatorDoorHeight) {
        this.elevatorDoorOpening = elevatorDoorWidth;
        this.elevatorDoorWidth = elevatorDoorWidth;
        this.elevatorDoorHeight = elevatorDoorHeight;
        setPreferredSize(new Dimension(elevatorDoorWidth*2, elevatorDoorHeight));
        try {
            bImg = ImageIO.read(new File("images/Door_Texture.jpg"));
        } catch (IOException ex) {
            Logger.getLogger(Door.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public void incrementOpening (int increment) {
        elevatorDoorOpening += increment;
    }
    
    public void setOpening(double ratioOpening) {
        elevatorDoorOpening = (int) (elevatorDoorWidth*ratioOpening);
    }
    
    public int getOpening() {
        return elevatorDoorOpening;
    }
    
    public int getElevatorWidth() {
        return elevatorDoorWidth;
    }
    
    public void draw(Graphics g, int xCoord, int yCoord) {
        Rectangle rectangleLeft = new Rectangle(xCoord, yCoord, 
                elevatorDoorWidth-elevatorDoorOpening, elevatorDoorHeight);
        Rectangle rectangleRight = new Rectangle(xCoord+elevatorDoorWidth+elevatorDoorOpening, yCoord, 
                elevatorDoorWidth-elevatorDoorOpening, elevatorDoorHeight);
        Graphics2D g2d = (Graphics2D) g;

        g2d.setPaint(new TexturePaint(bImg, new Rectangle(bImg.getWidth(), bImg.getHeight())));
        g2d.fill(rectangleLeft);
        g2d.fill(rectangleRight);
    }

}

